package fr.norsys.mapper.jndi;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import junit.framework.TestCase;
import fr.norsys.mapper.core.MapperException;
import fr.norsys.mapper.manager.MapperManager;
import fr.norsys.mapper.xml.XMLConfigurator;
import fr.norsys.mapper.xml.XMLConfiguratorException;

/**
 * Integration testing class for XML configuration and 
 * execution of a search query.
 * <p>
 * This class executes  a simple scenario of querying the 
 * telephone, mail and full name of a user in canam.ldif based
 * on its name and surname.
 * </p>
 * <p>
 * This class uses MockLdap as backend.
 * </p>
 * 
 * @author nono
 *
 */
public class XMLJNDISearchTest extends TestCase {

	
	private XMLConfigurator xc;
	private MapperManager mgr;

	protected void setUp() throws Exception {
		super.setUp();
		this.xc = new XMLConfigurator();
		this.mgr = new MapperManager();
		
	}

	public void test01Base() throws MapperException, XMLConfiguratorException {
		// parse XML configuration file
		xc.parse(Thread.currentThread().getContextClassLoader().getResourceAsStream("jndi-sample.xml"));
		// configure manager
		this.xc.configure(this.mgr);
		this.mgr.set("ldifsource","canam-personnes-sample.ldif");
		this.mgr.setConfigured();
		this.mgr.start();
		// execute query 
		SearchMapper sm = (SearchMapper)this.mgr.getMapper("telAndMail");
		/* populate input */
		Map input = new HashMap();
		input.put("nom", "FOURCADE");
		input.put("prenom", "Sandrine");
		List ret = sm.search(input,null);
		assertEquals(1,ret.size());
	}
}
